package com.wms.controller;

import com.wms.bean.PageBean;
import com.wms.bean.ResultBean;
import com.wms.core.R;
import com.wms.dto.WarehouseAddDTO;
import com.wms.entity.Kuqu;
import com.wms.service.StoreAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiImplicitParam;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "库区管理")
public class StoreAreaController {
    @Autowired
    StoreAreaService storeAreaService;

    @GetMapping("/SAall")
    @ApiOperation(value = "库区展示")
    public ResultBean querySA(){
        List<Map<String, Object>> resultList =storeAreaService.querySA();

        return R.success("查询结果",resultList);
    }







//    @ApiOperation("库区更新")
//    @PutMapping("/SAupda/{id}")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "warmArea",value = "温区名id",dataType = "Integer"),
//            @ApiImplicitParam(name = "caName",value = "仓库名id",dataType = "Integer"),
//            @ApiImplicitParam(name = "kuName",value = "库区名",dataType = "String"),
//            @ApiImplicitParam(name = "beizhu",value = "备注",dataType = "String"),
//            @ApiImplicitParam(name = "id",value = "对应id",dataType = "int",required = true,paramType = "path")
//    })
//    public ResultBean updaSA(@RequestParam Integer warmArea,
//                             @RequestParam Integer caName,
//                             @RequestParam String kuName,
//                             @RequestParam String beizhu,
//                             @PathVariable int id  ){
//        int n=storeAreaService.updaSA(warmArea,caName,kuName,beizhu,id);
//
//        return R.success("更改操作",n);
//    }
@ApiOperation("库区更新")
@PutMapping("/SAupda")
@ApiImplicitParams({
        @ApiImplicitParam(name = "warmArea",value = "温区名id",dataTypeClass = Integer.class,paramType = "query",required = false),
        @ApiImplicitParam(name = "ckName",value = "仓库名id",dataTypeClass = Integer.class,paramType = "query",required = false),
        @ApiImplicitParam(name = "kuName",value = "库区名",dataTypeClass = String.class,paramType = "query",required = false),
        @ApiImplicitParam(name = "beizhu",value = "备注",dataTypeClass = String.class,paramType = "query",required = false),
        @ApiImplicitParam(name = "id",value = "对应id",dataTypeClass = Integer.class,required = true,paramType = "query")
})
public ResultBean updaSA(@RequestParam("id") Integer id,  // 绑定前端的id参数
                         @RequestParam("caName") Integer ckName,  // 绑定前端的caName参数（映射到ckName）
                         @RequestParam("warmArea") Integer warmArea,  // 绑定前端的warmArea（字符串类型）
                         @RequestParam("kuName") String kuName,
                         @RequestParam("beizhu") String beizhu  ){
    System.out.println("后端接收的id值：" + id);
    System.out.println(id.getClass());
    if (id == null || id <= 0) {
        return R.fail("id无效");
    }
    int n=storeAreaService.updaSA(warmArea,ckName,kuName,beizhu,id);
    return R.success("更改操作",n);
}





    @ApiOperation("库区管理分页")
    @GetMapping("/SAfenye")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "单页显示条数",dataType = "int"),
    })
    public PageBean<Kuqu> fenyeSA(@RequestParam(defaultValue = "1") int page,
                                  @RequestParam(defaultValue = "5") int pageSize){
        PageBean pageBean=storeAreaService.fenyeSA(page,pageSize);
        return pageBean;
    }


    @GetMapping("/SAcha")
    @ApiOperation("条件筛选")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",dataType = "int",required = true),
            @ApiImplicitParam(name = "pageSize",value = "单页显示条数",dataType = "int",required = true),
            @ApiImplicitParam(name = "ckName",value = "仓库名",dataType = "String"),
            @ApiImplicitParam(name = "kuName",value = "库区名",dataType = "String")
    })
    public PageBean<Kuqu> chaByKu(@RequestParam(defaultValue = "1") int page,
                              @RequestParam(defaultValue = "5") int pageSize,
                              String ckName,String kuName){

        return storeAreaService.chaByKu(page,pageSize,ckName,kuName);
    }

    @PostMapping("/addKu")
    @ApiOperation("添加库区")
    public ResultBean addKu(@RequestBody WarehouseAddDTO warehouseAddDTO){

        return storeAreaService.addWarehouse( warehouseAddDTO);
    }

    @ApiOperation("删除库区")
    @DeleteMapping("/deleKU")
    @ApiImplicitParam(name = "id",value = "要删除的数据id",dataType = "int",required = true)
    public ResultBean deleKu(int id){
        int n=storeAreaService.deleKu(id);
        return R.success("删除",n);
    }

}
